home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / machack / Hacks97 / WarriorsProgress.sit / Warrior’s Progress / source code / Source / Libraries / Miscellany / New.cp < prev    next >
Text File  |  1997-06-28  |  644b  |  44 lines

  1. // New.cp
  2.  
  3. #ifndef New_h
  4. #include "New.h"
  5. #endif
  6. #ifndef MemoryFullError_h
  7. #include "MemoryFullError.h"
  8. #endif
  9. #ifndef __ERRORS__
  10. #include <Errors.h>
  11. #endif
  12. #ifndef Assert_h
  13. #include "Assert.h"
  14. #endif
  15.  
  16. void *operator new( uint32 size )
  17.   {
  18.     void *result = NewPtr( size );
  19.     OSErr error( MemError() );
  20.     
  21.     if ( error == memFullErr )
  22.         throw MemoryFullError();
  23.     
  24.     if ( error != noErr )
  25.         throw MemoryError( error );
  26.     
  27.     if ( result == 0 )
  28.         throw MemoryFullError();
  29.         
  30.     return result;
  31.   }
  32.  
  33. void operator delete( void *p )
  34.   {
  35.     Assert( p != 0 );
  36.     
  37.     if ( p == 0 )
  38.         return;
  39.     
  40.     DisposePtr( static_cast<Ptr>( p ) );
  41.     
  42.     MemoryError::Check().Throw();
  43.   }
  44.